<include file="Common:layout" />
<body style="background-color: rgb(255, 255, 255); overflow: auto; cursor: default; -moz-user-select: inherit;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>代理统计</h3>
                <h5>代理所有信息的数据统计</h5>
            </div>
        </div>
    </div>

    <div class="flexigrid">
        <div class="mDiv" style="height: 44px">
            <div class="ftitle">
                <h3>代理统计</h3>
                <h5></h5>
            </div>

            <form action="" class="navbar-form form-inline" method="post" onsubmit="return false;">
                <div class="sDiv" style="margin-right:50px">
                    <div class="sDiv2">
                        <!--排序规则-->
                        <input type="text" name="start_time" id="start_time" placeholder="开始时间" value="{$start_time}">
                        <input type="text" name="end_time" id="end_time" placeholder="结束时间" value="{$end_time}">
                        <input type="button" class="btn" value="搜索" onclick="ajax_get();"/>
                    </div>
                </div>
            </form>
        </div>

        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0">
                    <thead>
                    <tr>
                        <th class="sign" axis="col0">
                            <div style="width: 24px;"><i class="ico-check"></i></div>
                        </th>
                        <th align="center" abbr="article_title" axis="col6" class="mhover">
                            <div style="text-align: center; width:100px;" class="">代理排行</div>
                        </th>
                        <th align="center" abbr="article_title" axis="col6">
                            <div style="text-align: left; width:300px;" class="">代理名称</div>
                        </th>
                        <th align="center" abbr="ac_id" axis="col4">
                            <div style="text-align: center; width: 200px;" class="">代理ID</div>
                        </th>
                        <th align="center" abbr="ac_id" axis="col4">
                            <div style="text-align: center; width: 150px;" onclick="orderby('sumnum DESC')"><a>订单数量</a></div>
                        </th>
                        <th align="center" abbr="article_show" axis="col6">
                            <div style="text-align: center; width: 200px;" onclick="orderby('sumprice DESC')"><a>代理订单销售额</a></div>
                        </th>
                        <th style="width:100%" axis="col7">
                            <div></div>
                        </th>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table>
                    <tbody>
                    <foreach name="res" item="vo" key="k" >
                        <tr>
                            <td class="sign" axis="col0">
                                <div style="width: 24px;"><i class="ico-check"></i></div>
                            </td>
                            <td align="center" axis="col0">
                                <div style="width: 100px;text-align: left;">{$k+1}</div>
                            </td>
                            <td align="center" axis="co10">
                                <div style="width: 300px;text-align: left;">{$vo.agent_name}</div>
                            </td>
                            <td align="center" axis="col0">
                                <div style="text-align: center; width: 200px;">{$vo.agent_id}</div>
                            </td>
                            <td align="center" axis="col0">
                                <div style="text-align: center; width: 150px;">{$vo.sumnum}</div>
                            </td>
                            <td align="center" axis="col0">
                                <div style="text-align: center; width: 200px;">{$vo.sumprice}</div>
                            </td>
                            <td align="" class="" style="width: 100%;">
                                <div>&nbsp;</div>
                            </td>
                        </tr>
                    </foreach>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript" src="__PUBLIC__/usr/js/layer/laydate/laydate.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        // 表格行点击选中切换
        $('#flexigrid > table>tbody >tr').click(function () {
            $(this).toggleClass('trSelected');
        });
    });

    function ajax_get(){
        var start_time = $('#start_time').val();
        var end_time = $('#end_time').val();

        if(!start_time || !end_time){
            layer.msg("时间不能为空");return false;
        }

        var start_timestamp = Date.parse(new Date(start_time));
        start_timestamp = start_timestamp / 1000;

        var end_timestamp = Date.parse(new Date(end_time));
        end_timestamp = end_timestamp/1000;

        if(start_timestamp > end_timestamp){
            layer.msg("开始时间必须大于结束时间");return false;
        }
        $.ajax({
            url:"{:U('Report/agent_ranking')}",
            type:"post",
            data:{
                start_time : start_time,
                end_time : end_time
            },
            success:function (msg) {
                layer.msg("加载中...",{time:1000});
                setTimeout(function() {
                    $("#flexigrid").remove();
                    $(".bDiv").append(msg);
                }, 1000);
            }
        })
    }

    function orderby(data) {
        $.ajax({
            url:"{:U('Report/agent_ranking')}",
            type:"post",
            data:{
                orderby : data
            },
            success:function (msg) {
                layer.msg("加载中...",{time:700});
                setTimeout(function() {
                    $("#flexigrid").remove();
                    $(".bDiv").append(msg);
                }, 700);
            }
        })
    }

    $(function() {
        //日历插件
        $('#start_time').layDate();
        $('#end_time').layDate();
    });

</script>
</body>
</html>

